<?php
/**
*	
*/
class deptClassAction extends apiAction
{

	public function dataAction()
	{
		$id   = (int)$this->get('id','0');
		return $this->showdata($id);
	}
	
	private function showdata($id)
	{
		$rows = m('dept')->getall('cid='.$this->companyid.' and `pid`='.$id.'','*','sort desc,id asc');
		$arr  = array();
		foreach($rows as $k=>$rs){
			$nrs = array(
				'name' => $rs['name'],
				'id'	  => $rs['id'],
				'showid'  => $rs['id'],
				'showty'  => 'd',
				'isParent'=> true,
			);
			if($id==0){
				$nrs['children'] = $this->showdata($rs['id']);
				$nrs['open']	 = true;
			}
			$arr[] 	= $nrs;
		}
		$uarrs = m('usera')->getall('cid='.$this->companyid.' and `deptid`='.$id.' and `status` =1','*','sort desc');
		foreach($uarrs as $k=>$rs){
			$str = $rs['name'];
			if(!isempt($rs['position']))$str.='('.$rs['position'].')';
			$nrs = array(
				'name' 	 => $str,
				'showid' => $rs['id'],
				'showty' => 'a',
				'isParent'=> false,
			);
			$arr[] 	= $nrs;
		}
		return $arr;
	}
	
	/**
	*	选择
	*/
	public function datachangeAction()
	{
		$data = m('dept')->getData($this->adminid);
		return returnsuccess($data);
	}
}